//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

namespace Rendering {

	//---------------------------------------------------------------------
	// Generic Location methods
	//---------------------------------------------------------------------
	template<class T>
	GenericLocation<T>::GenericLocation ( const std::string& n, const T* r):
	IShaderLocation(n), ressource(r) {
	}
	//---------------------------------------------------------------------
	template<class T>
	GenericLocation<T>::~GenericLocation () {
	}
	//---------------------------------------------------------------------
	template<class T>
	void GenericLocation<T>::Enable() {
		Renderer::Instance().LoadShaderVariable(location, *ressource);
	}
	//---------------------------------------------------------------------
	template<class T>
	void GenericLocation<T>::Disable() {
		//TODO or nothing
	}
	//---------------------------------------------------------------------
	template<class T>
	void GenericLocation<T>::SetLocation(const ShaderLocalizator& localizator, ShaderCompilationReport& report) {		
		bool status = localizator.FindLocation(name, location);
		report.Report(name, location, status);
	}
	
	
	
	//---------------------------------------------------------------------
	// Texture Location methods
	//---------------------------------------------------------------------	
	template<class T>
	TextureLocation<T>::TextureLocation (const std::string& n, const Tools::SmartPointer<T>& t):
	IShaderLocation(n), 
	unit(DEFAULT_UNIT), 
	texture(t) {
	}	
	//---------------------------------------------------------------------
	template<class T>
	TextureLocation<T>::~TextureLocation() { 
	}	
	//---------------------------------------------------------------------
	template<class T>
	void TextureLocation<T>::Enable() {
		Renderer::Instance().LoadShaderVariable(location, texture, unit);
	}
	//---------------------------------------------------------------------
	template<class T>
	void TextureLocation<T>::Disable() {
	}
	//---------------------------------------------------------------------
	template<class T>
	void TextureLocation<T>::SetLocation(const ShaderLocalizator& localizator, ShaderCompilationReport& report) {
		bool status = localizator.FindLocation(name, location, unit);
		report.Report(name, location, unit, status);
	}
	
	
	
	//---------------------------------------------------------------------
	// Ressources Context Methods
	//---------------------------------------------------------------------
	template<class T>
	void RessourceContext::AddRessource(const std::string& name, const T& ressource) {
		TIShaderLocationPointer shaderLocation( new GenericLocation<T>(name, &ressource) );		
		locations.push_back(shaderLocation);
	}
	//---------------------------------------------------------------------
	template<class T>
	void RessourceContext::AddRessource(const std::string& name, const Tools::SmartPointer<T>& texture) {
		TIShaderLocationPointer shaderLocation( new TextureLocation<T>(name, texture) );
		locations.push_back(shaderLocation);
	}
	//---------------------------------------------------------------------
	
}